package edu.zhangxu.dao;

import edu.zhangxu.pojo.SubmitRecord;

import java.sql.Connection;
import java.util.List;

public class SubmitRecordDaoImp extends BaseDao implements SubmitRecordDao {
    @Override
    public List<SubmitRecord> getSubmitRecords(Connection con, int offset, int count) {
        String sql = "SELECT solutions.id,solutions.result,solutions.problem_id problemId,solutions.language," +
                       "solutions.time,solutions.memory,DATE_FORMAT(`judge_time`, \"%m-%d %H:%i:%S\") judgeTime,problems.name problemName" +
                       " FROM solutions INNER JOIN problems ON solutions.problem_id=problems.id" +
                       " ORDER BY solutions.id DESC LIMIT ?,?";
        return getList(con, SubmitRecord.class, sql, offset, count);
    }

    @Override
    public long getSubmitRecordTotal(Connection con) {
        String sql = "SELECT count(*) FROM solutions";
        return getValue(con, sql);
    }
}
